using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Backoffice.Infrastructure.Data;

public partial class FixPasswordHashMigration : Migration
{
    protected override void Up(MigrationBuilder migrationBuilder)
    {
        // 更新admin用户的密码哈希为BCrypt格式（对应密码"password"）
        migrationBuilder.Sql(@"
            UPDATE AppUsers 
            SET PasswordHash = '$2a$11$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi',
                UpdatedAt = GETUTCDATE(),
                UpdateBy = 'system'
            WHERE Username = 'admin' AND PasswordHash = '113'
        ");
    }

    protected override void Down(MigrationBuilder migrationBuilder)
    {
        // 回滚：恢复原来的密码哈希
        migrationBuilder.Sql(@"
            UPDATE AppUsers 
            SET PasswordHash = '113',
                UpdatedAt = GETUTCDATE(),
                UpdateBy = 'system'
            WHERE Username = 'admin' AND PasswordHash = '$2a$11$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi'
        ");
    }
} 